package com.ruoyi.review.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.review.domain.ReviewContent;
import com.ruoyi.review.service.IReviewContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.review.mapper.AppReviewMapper;
import com.ruoyi.review.domain.AppReview;
import com.ruoyi.review.service.IAppReviewService;

/**
 * 反馈管理Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-23
 */
@Service
public class AppReviewServiceImpl implements IAppReviewService {
    @Autowired
    private AppReviewMapper appReviewMapper;

    @Autowired
    private IReviewContentService iReviewContentService;

    /**
     * 查询反馈管理
     *
     * @param id 反馈管理主键
     * @return 反馈管理
     */
    @Override
    public AppReview selectAppReviewById(Long id) {
        AppReview appReview = appReviewMapper.selectAppReviewById(id);
        ReviewContent byId = iReviewContentService.getById(id.toString());
        appReview.setContent(byId.getContent());
        return appReview;
    }

    /**
     * 查询反馈管理列表
     *
     * @param appReview 反馈管理
     * @return 反馈管理
     */
    @Override
    public List<AppReview> selectAppReviewList(AppReview appReview) {
        List<AppReview> appReviews = appReviewMapper.selectAppReviewList(appReview);
        for (AppReview review : appReviews) {
            Long id = review.getId();
            ReviewContent byId = iReviewContentService.getById(id.toString());
            review.setContent(byId.getContent());
        }
        return appReviews;
    }

    /**
     * 新增反馈管理
     *
     * @param appReview 反馈管理
     * @return 结果
     */
    @Override
    public int insertAppReview(AppReview appReview) {
        appReview.setCreateTime(DateUtils.getNowDate());
        int i = appReviewMapper.insertAppReview(appReview);
        if (i > 0) {
            String content = appReview.getContent();
            Long id = appReview.getId();
            ReviewContent reviewContent = new ReviewContent();
            reviewContent.setContent(content);
            reviewContent.setId(id.toString());
            iReviewContentService.insert(reviewContent);
        }
        return i;
    }

    /**
     * 修改反馈管理
     *
     * @param appReview 反馈管理
     * @return 结果
     */
    @Override
    public int updateAppReview(AppReview appReview) {
        appReview.setUpdateTime(DateUtils.getNowDate());
        return appReviewMapper.updateAppReview(appReview);
    }

    /**
     * 批量删除反馈管理
     *
     * @param ids 需要删除的反馈管理主键
     * @return 结果
     */
    @Override
    public int deleteAppReviewByIds(Long[] ids) {
        return appReviewMapper.deleteAppReviewByIds(ids);
    }

    /**
     * 删除反馈管理信息
     *
     * @param id 反馈管理主键
     * @return 结果
     */
    @Override
    public int deleteAppReviewById(Long id) {
        iReviewContentService.delete(id.toString());
        return appReviewMapper.deleteAppReviewById(id);
    }
}
